package com.ice.netty.protobuf.server;

import org.springframework.stereotype.Component;

import com.ice.netty.protobuf.code.ProtobufMsgDecode;
import com.ice.netty.protobuf.code.ProtobufMsgEncode;
import com.ice.netty.protobuf.config.ProtoNettyTestConfig;
import com.ice.netty.protobuf.handle.ProtoDefaultProcess;
import com.ice.remoting.NettyRemotingServer;

import io.netty.channel.Channel;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class ProtoServer extends NettyRemotingServer {

    private ProtoNettyTestConfig nettyTestConfig;

    public ProtoServer(ProtoNettyTestConfig nettyTestConfig) {
        super(nettyTestConfig);
        this.nettyTestConfig = nettyTestConfig;
    }

    public void start() {
        super.start();
        this.registerDefaultProcessor(new ProtoDefaultProcess(this));
    }

    public void setCustomerUniqueIdentity(Channel channel, String customerUniqueIdentity) {
        this.getDeviceManager().setCustomerUniqueIdentity(channel, customerUniqueIdentity);
    }

    @Override
    public ByteToMessageDecoder buildDecoder() {
        return new ProtobufMsgDecode();
    }

    @Override
    public MessageToByteEncoder buildEncoder() {
        return new ProtobufMsgEncode();
    }
}
